package com.zzxx.wechat.service.impl;

import com.alibaba.fastjson.JSON;
import com.zzxx.wechat.common.vo.ArcteryxGiftReq;
import com.zzxx.wechat.exception.BusinessException;
import org.apache.http.HttpHost;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

public class App {
    public static void main(String[] args) {

//
//        // 配置参数  https://wbiprod.storedvalue.com/wbir/api/checkBalance
//     //   final String TARGET_URL = "https://wbiprod.storedvalue.com/wbir/api/checkBalance";
//     final String TARGET_URL = "https://arcteryx.com/us/en/shop/X000009141";
//      //  final String PROXY_HOST = "pr.oxylabs.io";
//       // final int PROXY_PORT = 7777;
//       // final String USERNAME = "customer-zhangxin_iUsnU-cc-US";
//       // final String PASSWORD = "awsAWS123+++";
//       final String PROXY_HOST = "brd.superproxy.io";
//        final int PROXY_PORT = 33335;
//        final String USERNAME = "brd-customer-hl_b3246fe5-zone-residential_proxy1-country-jp";
//        final String PASSWORD = "n62p45lthsqb";
//        // 创建凭证提供器
//        BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
//        credsProvider.setCredentials(
//                new AuthScope(PROXY_HOST, PROXY_PORT),
//                new UsernamePasswordCredentials(USERNAME, PASSWORD)
//        );
//
//        // 配置带代理和认证的HTTP客户端
//        try (CloseableHttpClient httpClient = HttpClients.custom()
//                .setDefaultCredentialsProvider(credsProvider)
//                .setProxy(new HttpHost(PROXY_HOST, PROXY_PORT))
//                .build()) {
//
//
//
//
//
//
//         //   String json = "{\"cardNumber\":\"6006496947757747369\",\"pinNumber\":\"8838\",\"host\":\"arcteryx\",\"locale\":\"en_US\",\"captchaType\":2,\"captcha\":\"03AFcWeA4SgSq164L-4NSE-F_7BVUIM3hZJEwyLXFVqI_7ySMAFmc4EiAy6t9U0qN-ylX_JSBace5RguS0rHvNSuDiZ4wVxrN0GOhWoZgZ7TggY9Czr1Y8PHgXuQ90A4hpSlW62ooujAwdNkoP_rYN1AqlAsmkLrbshqQKiPGReSC_2njkHQgyqmUUSQHoLEsO0QOyd6XM4pTgSBL7Eh9EZiJ4tUi1xH_mY6CtixK2uUnFydBwYbvqI73aMrM2SOR1Mmfa0-ZdVtRkBEznvN2MCRWEaUSWqkKN6-5aCM5VcYVz5onVW5-bnDcF_5o9PIj4e8FjBOK8wZaiZvZdllJMLaI2OHsSaBDFm9DeGfd1wyNH8Zh3XGqUSM6ZBUHrVsyM7wwLo0kGfifhoPk-gUaeaOCw9Y8eLejG5yIQDRLc8wEUYFmZzY07KwjUZbR1_iudhX5VhhTo6U_6GCLM0OqHMmV4-kDuLTMUFgjs_bzzaxIdQxUk3wuueaykTb-aBGiF3e-6rrBgiJymgtRtPYP_M3pqO4HtZT0p6l3-oJyd5UU1ugTNjTry3wOv1jeCwie0ELPc1xH2TzVgKrHMhoLekYhGx6p2vP01UIiKBWvIX9slchifthqScQUPaGgT7skOj4j-KstG2MmU5bmLSwm2oyBHWc3_6MzfbhktDxwKLXMgePzfXglsT95Hrres6konr4exGrJhyG2KK0UpuqzzY1rGUV-IOskaFzITC0um3eTZM8qWx0zweu8NyGAW32zEcWk8rNXEmbmZhfJHwyx2ebNKqhRD-LMzVRpkGsYn7l70exc-VqptxIZUN1oU-AHia-XBMOptQ8Dp7dV09fMrDOISsnGDJoBIN0rrsjQ_uY4-AJv2xjidjVkh8cEkyO6XhPwYCHG9tpoW_bQHvyRnLQ_JEGTEd7-ayBx4rS05ZEch3-WzJY_4qCBb67vQH3pau4iBjb7BiudLvsTWk5aWnA77_jAUHbVSwQ\",\"landTime\":1752485333375}";
//       //     String json = "{\"cardNumber\":\"6006496947757818228\",\"pinNumber\":\"4548\",\"host\":\"arcteryx\",\"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//         //   ArcteryxGiftReq arcteryxGiftReq = JSON.parseObject(json, ArcteryxGiftReq.class);
///*            ArcteryxGiftReq arcteryxGiftReq = new ArcteryxGiftReq();
//            arcteryxGiftReq.setCardNumber("6006496947757747369");
//            arcteryxGiftReq.setPinNumber("8838");*/
//        //    HttpPost httpPost = new HttpPost(TARGET_URL);// 创建httpPost
//
//
//
//
//            //
////
////            httpPost.setHeader("Accept", "application/json");
////            httpPost.setHeader("Content-Type", "application/json");
////            httpPost.setHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36");
////            httpPost.setHeader("Referer", "https://wbiprod.storedvalue.com/wbir/clients/arcteryx?lng=en");
////            httpPost.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
////
////
////            String cf = "{\"workTime\":1753084546341,\"id\":\"8b10beaea667052ace95363113a563d3\",\"answers\":[1,4],\"duration\":23,\"d\":-796,\"st\":1753084329489,\"rst\":1753084328693}\n";
////
////            httpPost.setHeader("Cookie", "KP_UIDz-ssn=02MneyDM6Q9Np6mdp8sBGy4kWnNbMmroKzlIU7hLwGl4hysyjD375OahQrjJSenxSHNq4OHbu29OFdV6OGsUkvu5QFvf6JulCr4i0cJZy42McmhXK9VM7HfrtPX568OZbAqJtePNkzWSNsDaJHJ9MRO9N3G3Nzoq5ITheAgztg; KP_UIDz=02MneyDM6Q9Np6mdp8sBGy4kWnNbMmroKzlIU7hLwGl4hysyjD375OahQrjJSenxSHNq4OHbu29OFdV6OGsUkvu5QFvf6JulCr4i0cJZy42McmhXK9VM7HfrtPX568OZbAqJtePNkzWSNsDaJHJ9MRO9N3G3Nzoq5ITheAgztg; TSdb2c6c26027=08109856a0ab2000853780702212311fbd2e1757da44d7a703a4e2d8bf365508e86fd38885127bdd081652b070113000c5368e4934b2b4cc4a07269fd9c86c81c54a50e5abf0829f0d712c5283c3afb8f7f594eaa2b7b1d5dddcb64e2424a334");
////            httpPost.setHeader("x-kpsdk-cd", JSON.parseObject(cf).toJSONString());
////            httpPost.setHeader("x-kpsdk-ct", "0KHb7Fq8ztOhOglpQ43BgWYX5YZIDkY0tiTEw0bEP4E18o4gxItz06QxUYzyCerlURXsIX73mD9lskljxkh32bNNc7YmJIj9coEj5v5eEJIrg0gAuu4lCy2XpwoV8BlxqzGPEay4Ds73qh9VhAhbSGECBswIqyz8gTYUkDRP5Pkr");
////            httpPost.setHeader("x-kpsdk-v", "j-1.1.0");
//          //  httpPost.setHeader("Accept", "application/json, text/plain, */*");
//          //  httpPost.setHeader("Accept-Encoding", "gzip, deflate, br, zstd");
///*            httpPost.setHeader("Accept-Language", "zh-CN,zh;q=0.9");
//         //   httpPost.setHeader("Content-Length", "1161");
//            httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
//            httpPost.setHeader("Cookie", "KP_UIDz-ssn=0b4HcvCLWSNhUAKDA4ezQmekFvI6o5keEtEgCOvxCSlap5huv7R2002eRKD2wO1Q7SQPocmRBuCI137VOTFXmCwdGe9WxzNLNVS1NCoNJZ3vmcRGDHdp5eB2gjzqQQkR6l9p8ph1KQTAzsv14lqDJrGATDYboFUBnJq2PgO");
//            httpPost.setHeader("Origin", "https://wbiprod.storedvalue.com");
//            httpPost.setHeader("Priority", "u=1, i");
//            httpPost.setHeader("Referer", "https://wbiprod.storedvalue.com/wbir/clients/arcteryx?lng=en");
//            httpPost.setHeader("sec-ch-ua", "\"Not)A;Brand\";v=\"8\", \"Chromium\";v=\"138\", \"Google Chrome\";v=\"138\"");
//            httpPost.setHeader("sec-ch-ua-mobile", "?0");
//            httpPost.setHeader("sec-ch-ua-platform", "\"Windows\"");
//            httpPost.setHeader("sec-fetch-dest", "empty");
//            httpPost.setHeader("sec-fetch-mode", "cors");
//            httpPost.setHeader("sec-fetch-site", "same-origin");
//            httpPost.setHeader("sec-fetch-storage-access", "active");
//            httpPost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36");
//            httpPost.setHeader("x-kpsdk-cd", "{\"workTime\":1753701995643,\"id\":\"f8d5f93335c227af1acaf9ba21d16f7f\",\"answers\":[10,3],\"duration\":57.4,\"d\":85,\"st\":1753701969115,\"rst\":1753701969200}");
//            httpPost.setHeader("x-kpsdk-ct", "0b4HcvCLWSNhUAKDA4ezQmekFvI6o5keEtEgCOvxCSlap5huv7R2002eRKD2wO1Q7SQPocmRBuCI137VOTFXmCwdGe9WxzNLNVS1NCoNJZ3vmcRGDHdp5eB2gjzqQQkR6l9p8ph1KQTAzsv14lqDJrGATDYboFUBnJq2PgO");
//            httpPost.setHeader("x-kpsdk-v", "j-1.1.0");*/
//
//
////            // 标准请求头
////            httpPost.setHeader("Accept", "application/json, text/plain, */*");
////       //     httpPost.setHeader("Accept-Encoding", "gzip, deflate, br, zstd");
////            httpPost.setHeader("Accept-Language", "zh-CN,zh;q=0.9");
////            httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
////            httpPost.setHeader("Origin", "https://wbiprod.storedvalue.com");
////            httpPost.setHeader("Referer", "https://wbiprod.storedvalue.com/wbir/clients/arcteryx?lng=en");
////            httpPost.setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36");
////
////// 安全相关头
////            httpPost.setHeader("Sec-Fetch-Dest", "empty");
////            httpPost.setHeader("Sec-Fetch-Mode", "cors");
////            httpPost.setHeader("Sec-Fetch-Site", "same-origin");
////
////// 自定义SDK头
////            httpPost.setHeader("x-kpsdk-cd", "{\"workTime\":1754056597301,\"id\":\"ad22f0c146133c9614c80a8c66ed4293\",\"answers\":[1,5],\"duration\":19.2,\"d\":-2053,\"st\":1754056006015,\"rst\":1754056003962}");
////            httpPost.setHeader("x-kpsdk-ct", "0929PjCL5xlhMqdot3WGXy5vBEHfyDvOw3yAvmKiQNPMWUTdYaaqpqdr3GoMORzwQzdv3JHn3ynXNZJrSgWDspca3gHEQv644H9DaGDZUasYrlwQDlzSB0nGrKET9arx2oebpNBxkTUbgE5tGcn5Z4ZimlTmhJRIPlEE3lk");
////            httpPost.setHeader("x-kpsdk-v", "j-1.1.0");
////
////// 敏感信息（建议动态获取）
////            httpPost.setHeader("cookie", "KP_UIDz-ssn=0929PjCL5xlhMqdot3WGXy5vBEHfyDvOw3yAvmKiQNPMWUTdYaaqpqdr3GoMORzwQzdv3JHn3ynXNZJrSgWDspca3gHEQv644H9DaGDZUasYrlwQDlzSB0nGrKET9arx2oebpNBxkTUbgE5tGcn5Z4ZimlTmhJRIPlEE3lk");
////
////// 请求优先级
////            httpPost.setHeader("Priority", "u=1, i");
////            String charSet = "UTF-8";
////            StringEntity entity = new StringEntity(JSON.toJSONString(arcteryxGiftReq), charSet);
////            httpPost.setEntity(entity);
//
//            // 执行请求并处理响应
//            try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
//                System.out.println("Response: " + EntityUtils.toString(response.getEntity()));
//            }
//
//        } catch (IOException e) {
//            System.err.println("HTTP请求失败: " + e.getMessage());
//            e.printStackTrace();
//        }
    }

    private static String queryProtocolAndDomain(String url) {
        try {
            URL arcteryxUrl = new URL(url);
            return arcteryxUrl.getProtocol() + "://" + arcteryxUrl.getHost() + "/";
        } catch (MalformedURLException e) {
            throw new BusinessException("链接输入有误，请重新输入");
        }
    }

}